import { localStorage } from '@/common/js/storage'

let baseURL = 'http://swoole_api.shuzi88.com';
const user = {
  state: {
    userInfo: localStorage.getItem('userInfo') || null,   //userInfo
    token: localStorage.getItem('token') || '',   //token
    RealmName: baseURL,                  //部署域名
    menuList: localStorage.getItem('menuList') || [] , //菜单列表,
    authList: localStorage.getItem('authList') || []
  },
  mutations: {
    ['USER_INFO'] (state, payload) {
      state.userInfo = payload || null;
    },
    ['MENU_List'] (state, payload) {
      state.menuList = payload || [];
      console.log(state.menuList);
    },
    ['AUTH_LIST'] (state, auth) {
      state.authList = auth;
      localStorage.setItem('authList', auth);
    },
    ['TOKEN'] (state, token) {
      state.token = token;
      localStorage.setItem('token', token);
    }
  },
  actions: {
    setUserInfo ({ commit }, payload) {
      if (payload) {
        localStorage.setItem('userInfo', payload)
      } else {
        localStorage.removeItem('userInfo')
      }
      commit('USER_INFO', payload)
    },
    setMenuList ({ commit }, payload) {
      if (payload) {
        localStorage.setItem('menuList', payload)
      } else {
        localStorage.removeItem('menuList')
      }
      commit('MENU_List', payload)
    },
  }
};
export default user;